﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.iss.inventory.Entity;

namespace com.iss.inventory.Controllers
{
    public class AddItemToVoucherController
    {
        public AddItemToVoucherController() { }

        public String[] getItemByBinNo(String txtGetItem)

        {
            InvManagementEntities IME = new InvManagementEntities();
            StationeryItem i;
            try
            {
                i = IME.StationeryItems.First<StationeryItem>(x => x.Location == txtGetItem);
            }
            catch (Exception ex) { return null; }
            String[] item = { i.Location, Convert.ToString(i.ItemID),i.Description, Convert.ToString(i.QtyLeft) };
            return item;
        }

        public String[] getItemByItemCode(String txtGetItem)
        {
            InvManagementEntities IME = new InvManagementEntities();
            StationeryItem i;
            try
            {
                var itemID = Convert.ToInt32(txtGetItem);
                i = IME.StationeryItems.First<StationeryItem>(x => x.ItemID == itemID);
            }
            catch (Exception ex) { return null; }

            String[] item = { i.Location, Convert.ToString(i.ItemID), i.Description, Convert.ToString(i.QtyLeft) };
            return item;
        }

        public String addAdjustmentVoucher(String lblItemID, String txtQtyAdjusted, String ddlReason, DateTime currentDate)
        {
            InvManagementEntities IME = new InvManagementEntities();
            var itemID = Convert.ToInt32(lblItemID);
            var QtyAdj = Convert.ToInt32(txtQtyAdjusted);
            AdjVoucherDetail avd = new AdjVoucherDetail();
            avd.ItemID = itemID; avd.QtyAdjust = QtyAdj; avd.Reason = ddlReason; avd.DateAdj = currentDate;
            IME.AddToAdjVoucherDetails(avd);
            IME.SaveChanges();
            return "Adjustment Voucher Submit Successfully";
        }
    }
}
